
Partial Class Search_AlertDetails
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            Dim AlertDetails As Cdm.DataCore.CaseNotes.AlertDisplay
            Dim supportBrokerId As Integer = Convert.ToInt32(Request("sid"))
            Dim alertId As Integer = Convert.ToInt32(Request("aid"))
            Dim participantId As Integer = Convert.ToInt32(Request("pid"))
            AlertDetails = Cdm.DataCore.CaseNotes.AlertDisplay.Retrieve(participantId, supportBrokerId, alertId)
            Me.DetailsTextbox.Value = AlertDetails.Description
            Me.IndividualTextbox.Value = AlertDetails.Individual
            Me.AlertDescriptionTextbox.Value = AlertDetails.Alerttext
            Me.PriorityLevelTextbox.Value = GetCriticalLevel(AlertDetails.CriticalLevel)
            If AlertDetails.SupportBrokerId > 0 Then
                Me.GoToDetailsButtion.Text = "View Support Broker Files"
            End If
            Me.ReturnURL.Value = Request.ServerVariables("HTTP_REFERER")
            UpdateViewed(AlertDetails)
        End If
    End Sub

    Private Sub UpdateViewed(ByVal alertDetails As Cdm.DataCore.CaseNotes.AlertDisplay)
        Try
            Dim usrAlert As New Cdm.DataCore.CaseNotes.UserAlert()
            usrAlert.AlertId = alertDetails.AlertId
            usrAlert.SupportBrokerId = alertDetails.SupportBrokerId
            usrAlert.ParticipantId = alertDetails.ParticipantId
            usrAlert.IsViewed = True
            usrAlert.CriticalLevel = alertDetails.CriticalLevel
            usrAlert.UserId = UserAuthorization.CurrentUser.UserId
            usrAlert.SetViewed()
            'Gentle.Framework.Broker.Update(usrAlert)
        Catch ex As Exception
            'Do nothing -- if the record is already there, we don't need to insert it.
            Dim s As String = ex.Message

        End Try

    End Sub

    Private Function GetCriticalLevel(ByVal criticalLevel As Integer) As String
        If criticalLevel = 1 Then
            Return "Normal"
        ElseIf criticalLevel = "2" Then
            Return "High"
        Else
            Return "Critical"
        End If
    End Function

    Protected Sub GoToDetailsButtion_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GoToDetailsButtion.Click
        If Me.SupportBrokerId > 0 Then
            Dim supportBrokerId As Integer = Convert.ToInt32(Request("sid"))
            Dim supportBroker As Cdm.DataCore.Entities.SupportBroker = Cdm.DataCore.Entities.SupportBroker.Retrieve(supportBrokerId)
            Response.Redirect("~/Search/SupportBrokerFiles.aspx?userid=" & supportBroker.UserId.ToString())
        Else
            Response.Redirect("~/Case/EditFile.aspx?participantid=" & Request("pid"))
        End If

    End Sub

    Private ReadOnly Property SupportBrokerId() As Integer
        Get
            If Request("sid") Is Nothing Then
                Return 0
            Else
                Return Convert.ToInt32(Request("sid"))
            End If
        End Get
    End Property

    Protected Sub BackButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BackButton.Click
        Response.Redirect(Me.ReturnURL.Value)
    End Sub
End Class

